//
//  LLModificationView.m
//  UserUse
//
//  Created by Yiwi on 16/10/17.
//  Copyright © 2016年 CJPC. All rights reserved.
//

#import "LLModificationView.h"

@interface LLModificationView (){
    UIView * _iconView;
    UIView * _nameView;
    UIView * _carNumView;
    UIButton * _bt;
}

@end

@implementation LLModificationView

-(void)setupSubView{
    self.backgroundColor = kColoeString(@"f4f4f4");
    _iconView = [UIView new];
    _iconView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_iconView];
    
    _nameView = [UIView new];
    _nameView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_nameView];
    
    _carNumView = [UIView new];
    _carNumView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_carNumView];
    
    UILabel * iconLabel = [UILabel new];
    iconLabel.text = @"头像";
    iconLabel.textColor = kColoeString(@"#333333");
    [_iconView addSubview:iconLabel];
    
    UIView * iconLayer = [UIView new];
    iconLayer.backgroundColor = kColoeString(@"#dedede");
    [self addSubview:iconLayer];
    
    
    UIView * carLayer = [UIView new];
    carLayer.backgroundColor = kColoeString(@"#dedede");
    [self addSubview:carLayer];
    
    UILabel * nameLabel = [UILabel new];
    nameLabel.text = @"姓名";
    nameLabel.textColor = kColoeString(@"#333333");
    [self addSubview:nameLabel];
    
    UILabel * carLabel = [UILabel new];
    carLabel.text = @"车牌号";
    carLabel.textColor = kColoeString(@"#333333");
    [self addSubview:carLabel];
    
    UIView * bottomLayer = [UIView new];
    bottomLayer.backgroundColor = kColoeString(@"#dedede");
    [self addSubview:bottomLayer];
    
    _iconButton = [UIButton new];
    _iconButton.backgroundColor = kColoeString(@"f4f4f4");
    _iconButton.layer.masksToBounds = YES;
    _iconButton.layer.cornerRadius = kScaleNum(35)/2;
    [_iconButton addTarget:self action:@selector(pickImage) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_iconButton];
    
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.equalTo(@(kScaleNum(59)));
    }];
    
    [iconLayer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.equalTo(_iconView.mas_bottom);
        make.height.equalTo(@(kScaleNum(0.4)));
    }];
    
    [_nameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(iconLayer.mas_bottom);
        make.height.equalTo(@(kScaleNum(59)));
    }];
    
    [carLayer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameView.mas_bottom);
        make.left.right.equalTo(self);
        make.height.equalTo(@(kScaleNum(0.6)));
    }];
    
    
    [_carNumView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(carLayer.mas_bottom);
        make.height.equalTo(@(kScaleNum(59)));
    }];
    
    [bottomLayer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_carNumView.mas_bottom);
        make.left.right.equalTo(self);
        make.height.equalTo(@(kScaleNum(0.6)));
    }];
    
    [iconLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kScaleNum(10));
        make.centerY.equalTo(_iconView.mas_centerY);
    }];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kScaleNum(8));
        make.centerY.equalTo(_nameView.mas_centerY);
    }];
    
    [carLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kScaleNum(8));
        make.centerY.equalTo(_carNumView.mas_centerY);
    }];
    
    [_iconButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_iconView.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-kScaleNum(8));
        make.width.height.equalTo(@(kScaleNum(35)));
        
    }];
    
    [self setupButton];


}

-(void)setupButton{
    _bt = [UIButton new];
    _bt.backgroundColor = kColoeString(@"#ff9a02");
    _bt.layer.masksToBounds = YES;
    _bt.layer.cornerRadius = kScaleNum(4);
    [_bt setTitle:@"提交" forState:UIControlStateNormal];
    [_bt addTarget:self action:@selector(commit) forControlEvents:UIControlEventTouchUpInside];
    _bt.titleLabel.textColor = kColoeString(@"ffffff");
    [self addSubview:_bt];
    [_bt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(_carNumView.mas_bottom).offset(kScaleNum(18));
        make.width.equalTo(@(kScaleNum(260)));
        make.height.equalTo(@(kScaleNum(35)));
    }];
}

-(void)setupNoLoginView{
    _textField = [UITextField new];
    [self addSubview:_textField];
    _textField.placeholder = @"请输入您姓名";
    _textField.clearsOnBeginEditing = YES;
    _textField.textAlignment = NSTextAlignmentRight ;
    _textField.font = [UIFont systemFontOfSize:16];
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_nameView.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-kScaleNum(8));
        make.height.equalTo(@(kScaleNum(35)));
        make.width.equalTo(@(kScaleNum(200)));
    }];
    
    _carTF = [UITextField new];
    [self addSubview:_carTF];
    _carTF.placeholder = @"请输入您车牌号";
    _carTF.clearsOnBeginEditing = YES;
    _carTF.textAlignment = NSTextAlignmentRight ;
    _carTF.font = [UIFont systemFontOfSize:16];
    [_carTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_carNumView.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-kScaleNum(8));
        make.height.equalTo(@(kScaleNum(35)));
        make.width.equalTo(@(kScaleNum(200)));
    }];
    LLUserModel *model = [LLUserHandle getUserData];
    if (model.UserName !=nil) {
        _textField.text = model.UserName;
    }
    if (model.usernumber != nil) {
        _carTF.text = model.usernumber;
    }
    if (model.UserIconUrl != nil) {
        [_iconButton sd_setImageWithURL:[NSURL URLWithString:model.UserIconUrl] forState:UIControlStateNormal placeholderImage:nil];
    }
    
    
    
}
-(void)pickImage{
    [self.delegate pickPhoto];
}

-(void)commit{
    [self.delegate commitUserName:_textField.text withUserCarNum:_carTF.text];
}
@end
